package com.itwn.comic.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itwn.comic.entity.User;
import com.itwn.comic.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Repository
public class UserService {

    @Autowired
    UserMapper userMapper ;


    public User userLoginByName(String username) {

        return this.userMapper.selectUserByName(username) ;
    }

    public PageInfo<User> queryUserByPage(Integer now, Integer size, String username) {

        PageHelper.startPage(now , size);
        List<User> list = userMapper.selectUserByCons(username);

        return new PageInfo<>(list) ;
    }

    public void addUser(User user) {
        this.userMapper.insert(user) ;
    }

    public void modifyUser(User user) {
        this.userMapper.updateByPrimaryKey(user) ;
    }

    public void removeUserById(int id) {
        this.userMapper.deleteByPrimaryKey(id) ;
    }

    public void modifyUserStatusByCons(Integer uid, Integer status) {

        this.userMapper.updateStatusByCons(uid , status);
    }
}
